package com.crm.custinfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.crm.common.Page;
import com.crm.custinfo.po.CustInfo;
import com.crm.dao.CommonDAO;

public class CustInfoDAO extends CommonDAO implements ICustInfoDAO {

	public List getCustInfoList(CustInfo custInfo, HttpServletRequest request) {
		Page page = new Page();
		int currentPage = page.getCurrentPage(request);
		Integer count = (Integer) this.getSqlMapClientTemplate()
				.queryForObject("CustInfo.getCustInfoCount", custInfo);
		page.setRscount(count.intValue());
		int pagesize = page.getPagesize();
		String pagetool = page.pagetool(request.getRequestURI()+ page.getParams(request));
		request.setAttribute("pagetool", pagetool);

		List list = this.getSqlMapClientTemplate().queryForList(
				"CustInfo.getCustInfoList", custInfo,
				(currentPage - 1) * pagesize, pagesize);
		return list;
	}
	public List getBlackCustList(CustInfo custInfo, HttpServletRequest request) {
		Page page = new Page();
		int currentPage = page.getCurrentPage(request);
		Integer count = (Integer) this.getSqlMapClientTemplate()
		.queryForObject("CustInfo.getCustInfoCount", custInfo);
		page.setRscount(count.intValue());
		int pagesize = page.getPagesize();
		String pagetool = page.pagetool(request.getRequestURI()+  page.getParams(request));
		request.setAttribute("pagetool", pagetool);
		
		List list = this.getSqlMapClientTemplate().queryForList(
				"CustInfo.getCustInfoList", custInfo,
				(currentPage - 1) * pagesize, pagesize);
		return list;
	}
	public List getQueryCustList(CustInfo custInfo, HttpServletRequest request) {
		Page page = new Page();
		int currentPage = page.getCurrentPage(request);
		Integer count = (Integer) this.getSqlMapClientTemplate()
		.queryForObject("CustInfo.getCustInfoCount", custInfo);
		page.setRscount(count.intValue());
		int pagesize = page.getPagesize();
		String pagetool = page.pagetool(request.getRequestURI()+ page.getParams(request));
		request.setAttribute("pagetool", pagetool);
		
		List list = this.getSqlMapClientTemplate().queryForList(
				"CustInfo.getCustInfoList", custInfo,
				(currentPage - 1) * pagesize, pagesize);
		return list;
	}

	public boolean addCustInfo(CustInfo custInfo) {
		this.getSqlMapClientTemplate().insert("CustInfo.insertCustInfo", custInfo);
		return true;
	}

	public CustInfo getCustInfo(Integer id) {
		return (CustInfo) this.getSqlMapClientTemplate().queryForObject("CustInfo.getCustInfo", id);
	}
	public CustInfo getCustInfoByPhone(String phone) {
		return (CustInfo) this.getSqlMapClientTemplate().queryForObject("CustInfo.getCustInfoByPhone", phone);
	}
	public boolean delCustInfo(Integer id) {
		int i = this.getSqlMapClientTemplate().delete("CustInfo.delCustInfo", id);
		return i > 0 ? true:false;
	}

	public boolean updateCustInfo(CustInfo custInfo) {
		int i = this.getSqlMapClientTemplate().update("CustInfo.updateCustInfo", custInfo);
		return i > 0 ? true:false;
	}
	public boolean updateCustState(Integer id,String state) {
		Map map = new HashMap();
		map.put("id", id);
		map.put("state", state);
		int i = this.getSqlMapClientTemplate().update("CustInfo.updateCustState", map);
		return i > 0 ? true:false;
	}

}
